<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>HTTP/REST clients and security | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'http-clients.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/http-clients.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/http-clients.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/http-clients.html" rel="nofollow" target="_blank">../en/http-clients.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="secure-cluster.html">Secure a cluster</a></span>
»
<span class="breadcrumb-link"><a href="ccs-clients-integrations.html">Cross cluster search, clients, and integrations</a></span>
»
<span class="breadcrumb-node">HTTP/REST clients and security</span>
</div>
<div class="navheader">
<span class="prev">
<a href="java-clients.html">« Java Client and security</a>
</span>
<span class="next">
<a href="hadoop.html">ES-Hadoop and Security »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="http-clients"></a>HTTP/REST clients and security<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/ccs-clients-integrations/http.asciidoc">edit</a>
</h2>
</div></div></div>
<p>The Elasticsearch security features work with standard HTTP
<a href="https://en.wikipedia.org/wiki/Basic_access_authentication" class="ulink" target="_top">basic authentication</a>
headers to authenticate users. Since Elasticsearch is stateless, this header must
be sent with every request:</p>
<div class="pre_wrapper lang-shell">
<pre class="programlisting prettyprint lang-shell">Authorization: Basic &lt;TOKEN&gt; <a id="CO495-1"></a><i class="conum" data-value="1"></i></pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO495-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">&lt;TOKEN&gt;</code> is computed as <code class="literal">base64(USERNAME:PASSWORD)</code></p>
</td>
</tr>
</table>
</div>
<h4>
<a id="_client_examples"></a>Client examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/ccs-clients-integrations/http.asciidoc">edit</a>
</h4>
<p>This example uses <code class="literal">curl</code> without basic auth to create an index:</p>
<div class="pre_wrapper lang-shell">
<pre class="programlisting prettyprint lang-shell">curl -XPUT 'localhost:9200/idx'</pre>
</div>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "error":  "AuthenticationException[Missing authentication token]",
  "status": 401
}</pre>
</div>
<p>Since no user is associated with the request above, an authentication error is
returned. Now we’ll use <code class="literal">curl</code> with basic auth to create an index as the
<code class="literal">rdeniro</code> user:</p>
<div class="pre_wrapper lang-shell">
<pre class="programlisting prettyprint lang-shell">curl --user rdeniro:taxidriver -XPUT 'localhost:9200/idx'</pre>
</div>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "acknowledged": true
}</pre>
</div>
<h4>
<a id="_client_libraries_over_http"></a>Client libraries over HTTP<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/security/ccs-clients-integrations/http.asciidoc">edit</a>
</h4>
<p>For more information about using security features with the language
specific clients, refer to:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.7/_basic_authentication.html" class="ulink" target="_top">Java</a>
</li>
<li class="listitem">
<a href="https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html" class="ulink" target="_top">JavaScript</a>
</li>
<li class="listitem">
<a href="https://www.elastic.co/guide/en/elasticsearch/client/net-api/master/configuration-options.html" class="ulink" target="_top">.NET</a>
</li>
<li class="listitem">
<a href="https://metacpan.org/pod/Search::Elasticsearch::Cxn::HTTPTiny#CONFIGURATION" class="ulink" target="_top">Perl</a>
</li>
<li class="listitem">
<a href="https://www.elastic.co/guide/en/elasticsearch/client/php-api/master/security.html" class="ulink" target="_top">PHP</a>
</li>
<li class="listitem">
<a href="https://elasticsearch-py.readthedocs.io/en/master/#ssl-and-authentication" class="ulink" target="_top">Python</a>
</li>
<li class="listitem">
<a href="https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#authentication" class="ulink" target="_top">Ruby</a>
</li>
</ul>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="java-clients.html">« Java Client and security</a>
</span>
<span class="next">
<a href="hadoop.html">ES-Hadoop and Security »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>